define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            var ids = $("#ids").val();

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'jdklog/index' + location.search,
                    add_url: 'jdklog/add?ids='+ids,
                    edit_url: 'jdklog/edit',
                    del_url: 'jdklog/del',
                    multi_url: 'jdklog/multi',
                    import_url: 'jdklog/import',
                    table: 'jdklog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'jid', title: __('Jid'), operate: 'LIKE'},
                        // {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'dkks', title: __('Dkks'), operate: 'LIKE'},
                        {field: 'zfip', title: __('游戏服务器ip'), operate: 'LIKE'},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},

                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                if (row.status == 0){
                                    $(table).data("operate-edit", true); //编辑operate-edit  - 删除按钮operate-del
                                }else {
                                    $(table).data("operate-edit", null); // 列表页面编辑按钮隐藏
                                }
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }
                        }



                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
